package com.atguigu.gmall.activity.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 秒杀相关的交换机和队列绑定的创建
 * @author 搭忆长安
 * @version 1.0
 * @date 2021年07月16日 18:23
 * @ClassName:SeckillRabbitConfig
 * @Description: TODO
 */
@Configuration
public class SeckillRabbitConfig {
    /**
     * 创建秒杀的交换机
     * @return
     */
    @Bean("seckillExchange")
    public Exchange seckillExchange(){

        return ExchangeBuilder.topicExchange("seckill_exchange").build();
    }

    /**
     * 创建秒杀的队列
     * @return
     */
    @Bean("seckillQueue")
    public Queue seckillQueue(){
        return QueueBuilder.durable("seckill_queue").build();
    }
    @Bean
    public Binding seckillBinding(@Qualifier("seckillExchange")Exchange seckillExchange,
                                  @Qualifier("seckillQueue")Queue seckillQueue){
       return BindingBuilder.bind(seckillQueue).to(seckillExchange).with("seckill.#").noargs();
    }
}
